package com.xuxin.baby.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.LogUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.xuxin.baby.R;
import com.xuxin.baby.bean.MainMenuBean;
import com.xuxin.baby.glide.GlideApp;
import com.xuxin.baby.network.Retrofit;

import org.jetbrains.annotations.NotNull;

/**
 * Created by xu_xin
 * Created on 2020.08.04 0004
 * 主页功能列表
 */
public class MainMenuAdapter extends BaseQuickAdapter<MainMenuBean, BaseViewHolder> {
    private int checkPosition = 0;

    public MainMenuAdapter() {
        super(R.layout.item_main_menu);
    }

    public void refresh(int position) {
        checkPosition = position;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, MainMenuBean item) {
        LinearLayout item_main_menu = holder.getView(R.id.item_main_menu);
        holder.setText(R.id.item_main_menu_name, item.getName());
        ImageView item_main_menu_line = holder.getView(R.id.item_main_menu_line);
        if (checkPosition == holder.getAdapterPosition()) {
            item_main_menu_line.setVisibility(View.VISIBLE);
            item_main_menu.setBackgroundColor(ColorUtils.getColor(R.color.colorWhite));
        } else {
            item_main_menu_line.setVisibility(View.INVISIBLE);
            item_main_menu.setBackgroundColor(ColorUtils.getColor(R.color.colorBackground));
        }
        ImageView item_main_menu_image = holder.getView(R.id.item_main_menu_image);
        if (holder.getAdapterPosition() == 0) {
            GlideApp.with(getContext()).load(R.mipmap.img_health_growth).placeholder(R.mipmap.img_placeholder160).centerCrop().into(item_main_menu_image);
        } else {
            String image = Retrofit.image_url + item.getImage();
            LogUtils.e("主页功能列表_image = " + image);
            GlideApp.with(getContext()).load(image).placeholder(R.mipmap.img_placeholder160).centerCrop().into(item_main_menu_image);
        }
    }
}